* Summary statistics and plots of bills/laws

clear all
set more off
set scheme lean2

include "bill-analysis/bill_setup.do"

// graphs and summary stats
loc shootvars "`shoot' `fatal' `murder'"

gen news_x_shoot = news if `shoot' == 1
la var news_x_shoot "News conditional on shooting"

sumtable `billdv' `lawdv' laws_tighten laws_loosen `shoot' `fatal' `murder'  /*
    */ news news_x_shoot `politics' `gov' `demo' `rng'                       /*
    */ using "`out'/summary_stats.xlsx", sheet("Summary Stats", replace)     /*
    */ stats(mean sd p5 p10 p50 p90 p95 count) replace

xtset fips year
gen byte lagshoot = L.`shoot'
tab demleg repleg `rng'
tab demleg lagshoot `rng'
tab repleg lagshoot `rng'

// graph bills and laws by year
cap mkdir "`out'/fig"
preserve
    collapse (sum) `billdv' `lawdv' laws_tighten laws_loosen `rng', by(year) fast

	// Figure 3 in published paper
    twoway conn `billdv' `lawdv' year, m(o o) legend(off) /*
            X Axis
        */ xlabel(1990(2)2014, angle(90) labsize(small)) /*
        */ xtitle("Year", size(small)) /*
            Y Axis
        */ ylabel(0(200)1800, labsize(small) nogrid) /*
        */ ytitle("Count of Legislation", size(small)) /*
            Label Series
        */ text(1250 1993 "Bills Introduced", place(e) size(small)) /*
        */ text(250 1993 "Laws Enacted", place(e) size(small))

    cap graph export "`out'/fig/bill_timetrend.pdf", replace
    capture window manage close graph _all

    // tighten and loosen over time
    twoway conn laws_tighten laws_loosen year, m(sh o) legend(off) /*
        */ xlabel(1990(1)2014, angle(90) labsize(small)) /*
        */ ylabel(, labsize(small) nogrid) /*
        */ xtitle("Year", size(small)) ylab(0(10)70, labsize(small)) /*
        */ ytitle("Number of Laws", size(small)) /*
        */ text(15 1997 "Loosen", size(small)) /*
        */ text(42 1997 "Tighten", size(small))
    cap graph export "`out'/fig/tighten_loosen.pdf", replace
restore


// means by party control

tabstat `billdv' `lawdv' laws_tighten laws_loosen `rng' /*
    */ , by(legis_control) stats(mean sd p50 N)


// summarize law coding

use "data/lawcounts.dta" if inrange(year, 1990, 2014) & usps != "DC", clear

egen long total_laws = rowtotal(laws_*)
qui sum total_laws
assert r(sum) == 3199  // must match count in paper text

collapse (sum) total_laws laws_*, fast
reshape long laws_, i(total_laws) j(kind) string
rename laws_ laws
gen pct = 100 * laws / total_laws

list , sep(0)

export delim "`out'/law_coding_summary.csv", replace

exit
